import yjTabs from "./tabs";
import icon from "./icon";
import form from "./form";

import sideFoldPop from "./sideFoldPop";
import yjButton from "./buttton";
import yjLayout from "./layout";
import SvgIcon from "./icon/svgIcon.vue"; // svg组件
import menus from "./menu";
import dropdowns from "./dropdown";
import other from "./other";
import Vue from "vue";
import debounce from "./directive/debounce";
import { lyColorpiker } from "./other/colorPick/colorPick.js";
import notice from "./notice";
import lyMask from "./notice/mask/lyMask.vue";
import rightPanel from "./RightPanel";
const components = {
  rightPanel,
  lyMask,
  ...form,
  ...yjTabs,
  icon,
  yjButton,
  ...yjLayout,
  SvgIcon,
  ...menus,
  ...dropdowns,
  ...other,
};
const jsCpt = {
  ...notice,
  $lyColorpiker(arg) {
    return new lyColorpiker(arg);
  },
  ...sideFoldPop,
  $bus: new Vue({
    methods: {
      emit(event, ...args) {
        this.$emit(event, ...args);
      },
      on(event, ...args) {
        this.$on(event, ...args);
      },
      off(event, cb) {
        this.$off(event, cb);
      },
    },
  }),
};
const install = (Vue) => {
  Vue.directive("debounce", debounce);
  for (let key in jsCpt) {
    // 如果Vue原型对象没有改方法
    if (!Vue.prototype.hasOwnProperty(key)) {
      Vue.prototype[key] = jsCpt[key];
    } else {
      console.warn("属性" + key + "被占用");
    }
  }
  Object.keys(components).forEach((cpt) => {
    Vue.component(components[cpt].name, components[cpt]);
  });
  // 注册svg雪碧图
  const resvg = require.context("@/examples/assets/icons/svg", false, /\.svg$/);
  const requireAll = (requireContext) =>
    requireContext.keys().map(requireContext);
  requireAll(resvg);
};
export default {
  install,
};
